package com.bawei.bydayzg_two.adapter

import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.room.Index.Order
import com.bawei.base.bean.OrderItem0
import com.bawei.bydayzg_two.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class OrderAdapter:BaseQuickAdapter<OrderItem0,BaseViewHolder>(R.layout.item_order) {
    override fun convert(holder: BaseViewHolder, item: OrderItem0) {
        holder.setText(R.id.order_time,item.createTime)
        holder.setText(R.id.order_status,item.orderStatus)
        holder.setText(R.id.order_total,"共${item.totalNum}件商品，金额：￥${item.payPrice}")

        //
        val rv = holder.getView<RecyclerView>(R.id.order_rv)
        val orderChildAdapter = OrderChildAdapter()
        orderChildAdapter.data.addAll(item.orderInfoList)
        //
        rv.adapter = orderChildAdapter
        rv.layoutManager = LinearLayoutManager(context)

        //
        if (item.orderStatus == "待支付"){
            holder.getView<TextView>(R.id.order_tv2).text = "去支付"
        } else if (item.orderStatus == "待发货"){
            holder.getView<TextView>(R.id.order_tv2).text = "查看详情"
            holder.getView<TextView>(R.id.order_tv1).text = "申请售后"
        } else if (item.orderStatus == "待评价"){
            holder.getView<TextView>(R.id.order_tv2).text = "去评价"
        } else {
            holder.getView<TextView>(R.id.order_tv2).text = "查看详情"
        }
    }
}